tekkitclassicfandomcom-20200214-history
Tutorial/Redpower Programming
Programming Setting up To set up your basic computer you'll need: *Central Processing Unit as a base *Disk Drive (RedPower) to load and save your programs *Monitor (RedPower) to interact with the computer *FORTH Boot Disk to boot a default OS You may also need : *Ribbon Cable to separate blocks from each other *IO Expander to interact with existing redstone circuits All components must form a connected network. If you want them to be far away from each other, use Ribbon Cable. If you use the IO Expander, take care on the Ribbon Cable and Bundled Cable sides. Starting up To start up your computer, insert the FORTH Boot Disk in the Disk Drive (RedPower), then right click the CPU and click start. Now you may use the monitor. Programming Redpower computers use FORTH, a stack based programming language, meaning it primarily operates on the most recent values in memory, unlike modern languages like Java with a more organized structure. For example, typing 1 2 3 4 5 + pushes 1-5 into memory. Typing '.S' will display .S 1 2 3 9 because the last two values (4 and 5) are added into 9. Entering '+' further eventually results in a single value of 15. This is a list of the commands available : If you want to make a program you type ': *name of program*' and if you're done type ';'. So for example : : hello ." Hello World" ; Redstone outputs if you want a redstone output use '*value* IOX!' Multiple colors can be chosen by adding their values together. For example, to select white and orange, use 3, since 1 + 2 = 3. To do yellow and lime you use 48, since 16 + 32 = 48. You can also use binary conversion - search for the positions of 1's in the binary value. The position, starting from the right, corresponds to the color. For example, 48 is 110000 in binary. Because the 5th and 6th position corresponds to yellow and lime, 48 is yellow and lime. Looping When you're able to turn on lights or open and close doors using a redpower computer, you may want learn how to create loops. If you wanted to make a light flash on and off repeatedly, you could do the following: #Create a new program ': Flash' for example #Type 'Number of times you want it to flash' '0' 'DO' #Then type 'number of ticks you want to wait until it turns off' 'TICKS' #'value of your wire as seen above' 'IOX!' #Then type 'number of ticks you want to wait until it turns on' 'TICKS' #Then type '''0 IOX!' ''so lights will turn off #Finally, type '''LOOP ;' ''to end both your loop and function '''' For *1 it should look like this : Flash 10 0 DO 10 TICKS 1 IOX! 10 TICKS 0 IOX! LOOP ; This program will flash 10 times for the output 1 (White cable). But because splitting line does not matter in FORTH this could also be written as follows : : Flash 10 0 DO 10 TICKS 1 IOX! 10 TICKS 0 IOX! LOOP ; Now if you do not know how many times you want the flash, try this : : Flash 0 DO 10 TICKS 1 IOX! 10 TICKS 0 IOX! LOOP ; This will use the last value on the stack as the missing parameter for DO and will flash the number of times you type before flash - '2 Flash' will flash 2 times. More information You may want to read more about FORTH : http://technicpack.wikia.com/wiki/Basic_Forth_Programming http://technicpack.wikia.com/wiki/Forth_language Creating your own OS : http://wishstudio.blogspot.fr/2012/10/building-red-power-operating-system.html http://www.eloraam.com/nonwp/redcpu.php An example of another OS : https://github.com/vadixidav/minebos Tutorials Category:RedPower Control Category:Tutorials